// pages/my/signRed/signRed.js
var utils = require("../../../utils/utils.js");
Page({

    /**
     * 页面的初始数据
     */
    data: {
        canshow:true,
        cansshow:false,
    },
    qdl() {
        var that = this;
        wx.showLoading({
            title: '请稍候',
        })
        utils.request('sign/doSign', {}, function (res) {
            that.setData({
                thisMoney:res.data.data.todayAmount,
                tomorrowMoney:res.data.data.tomorrowAmount
            })
            that.getIndex();
            that.animation();
        })
    },
    getIndex() {
        var that = this;
        wx.showLoading()
        utils.request('sign/signListsByWeek', {}, function (res) {
            wx.hideLoading();
            var isSign = 0;
            for(var i=0;i<res.data.data.weekList.length;i++){
                if(res.data.data.weekList[i].date==res.data.data.currentDay){
                    isSign = res.data.data.weekList[i].isSign
                }
            }
            that.setData({
                amount: res.data.data.signTotalAmount,
                continuousDay: res.data.data.continuityDay,
                signList: res.data.data.weekList,
                date: res.data.data.birthday,
                isSign:isSign
            })
            that.getStar()
        })
    },
    goList(){
        wx.navigateTo({
          url: '/pages/my/signList/signList',
        })
    },
    bindDateChange(e){
        this.setData({
            date: e.detail.value
        })
    },
    starSerach(){
        if (!utils.is_define(this.data.date)) {
            utils.toast('请先选择您的生日');
           return false;
        }
        this.getStar()
    },
    getStar() {
        var that = this;
        if (!utils.is_define(that.data.date)) {
            wx.hideLoading()
            return false;
        }
        wx.showLoading()
        utils.request('user/starLucky', {
            birthday: that.data.date
        }, function (res) {
            wx.hideLoading()
            that.setData({
                starData: res.data.data
            })
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        var datetime = new Date();
        var year = datetime.getFullYear();
        var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
        var day = datetime.getDate()<10?"0"+datetime.getDate():datetime.getDate()
        var newDate = year+'-'+month+'-'+day
        this.setData({
            endTime:newDate,
            date:newDate
        })
        // this.selectComponent('#pm').animation();
        this.getIndex()
        // this.animation();

    },
    animation() {
        this.setData({
            coinShow: false,
            isShow: true
        })
        this.bgAnimation()
        this.smallAnimation()
        // this.redta();
        
        setTimeout(() => {
            this.imgroat();
        },2000)

    },
    bgAnimation() {
        var animation = wx.createAnimation({
            duration: 1000,
            timingFunction: 'ease-in-out',
        })
        setTimeout(() => {
            animation.translate3d(0, 30, 0).step().translate3d(0, 0, 0).step().rotate(80).step({
                duration: 400
            }).rotate(0).step({
                duration: 500
            })
            this.setData({
                bgCoinAnimation: animation.export()
            })
        }, 100)
        setTimeout(() => {
            animation.opacity(0).scale(4).step()
            this.setData({
                bgCoinAnimation: animation.export()
            })
        }, 3000)
    },
    imgroat(){
        this.setData({
            canshow:true
        })
        var animation = wx.createAnimation({
            duration:2000,
            timingFunction: 'ease-in',
        })
        var animation1 = wx.createAnimation({
            duration:2000,
            timingFunction: 'ease-in',
        })
        animation1.width('618rpx').height('950rpx').rotateY(360).left('66rpx').step({
            duration:1800
        });
        animation.width('618rpx').height('688rpx').step({
            duration:1800
        });
        setTimeout(() => {
            this.setData({
                coinAnimation8: animation1.export(),
                coinAnimation9: animation.export()
            })
        }, 300)
        setTimeout(() => {
            var audio = wx.createInnerAudioContext()
            audio.src = '/static/gold.mp3'
            audio.play()
            this.setData({
                cansshow:true
            })
        }, 2000)
    },
    knowbtn(){
        this.setData({
            canshow:false,
            canshow:false,
            isShow:false,
            imgw:'20rpx',
            imgh:'20rpx'
        })
    },
    smallAnimation() {
        var animation = wx.createAnimation({
            duration: 1000,
            timingFunction: 'ease-in-out',
        })
        animation.translate3d(0, 30, 0).step().translate3d(0, 0, 0).step()
        setTimeout(() => {
            this.setData({
                coinAnimation1: animation
            })
        }, 300)
        setTimeout(() => {
            this.setData({
                coinAnimation2: animation
            })
        }, 500)
        setTimeout(() => {
            this.setData({
                coinAnimation3: animation
            })
        }, 600)
        setTimeout(() => {
            this.setData({
                coinAnimation4: animation
            })
        }, 700)
        setTimeout(() => {
            this.setData({
                coinAnimation5: animation
            })
        }, 800)
        setTimeout(() => {
            this.setData({
                coinAnimation6: animation
            })
        }, 900)
        setTimeout(() => {
            this.setData({
                coinAnimation7: animation.export()
            })
        }, 1000)
        //小金币掉落动画
        setTimeout(() => {
            animation.translate3d(0, 1000, 0).step()
            this.setData({
                coinAnimation1: animation,
                coinAnimation2: animation,
                coinAnimation3: animation,
                coinAnimation4: animation,
                coinAnimation5: animation,
                coinAnimation6: animation,
                coinAnimation7: animation
            })
        }, 3000)
        //动画结束，重置动画初始位置
        setTimeout(() => {
            this.setData({
                coinShow: true
            })
            var animation = wx.createAnimation({
                duration: 300,
                timingFunction: 'ease-in-out',
            })
            var animation2 = wx.createAnimation({
                duration: 300,
                timingFunction: 'ease-in-out',
            })
            animation.translate3d(0, -1000, 0).step()
            animation2.translate3d(0, -1000, 0).step().scale(1).step()
            this.setData({
                bgCoinAnimation: animation2.export(),
                coinAnimation1: animation,
                coinAnimation2: animation,
                coinAnimation3: animation,
                coinAnimation4: animation,
                coinAnimation5: animation,
                coinAnimation6: animation,
                coinAnimation7: animation,
            })
            // setTimeout(() => {
            //     this.setData({
            //         isShow: false
            //     })
            // }, 500)
        }, 4000)
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        var that = this;
        if (that.data.firstOpen == 1) {
          this.getIndex()
        } else {
          that.setData({
            firstOpen: 1
          })
        }
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    }
})